home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / Small Demos / reverse.icl < prev    next >
Encoding:
Text File  |  1995-03-27  |  469 b   |  28 lines  |  [TEXT/3PRM]

  1. module reverse
  2.  
  3. //    A list containing n elements will be reversed n times.
  4.  
  5. import StdEnv
  6.  
  7. NrOfTimes :== 1000
  8.     
  9. //    Reversing a list of n integers n times.
  10.  
  11. MyReverse::Int -> Int
  12. MyReverse n =  last (Rev_n n [1..n])
  13. where
  14.     Rev_n::Int [Int] -> [Int]
  15.     Rev_n 1 list    =  Rev list []
  16.     Rev_n n list    =  Rev_n (n - 1) (Rev list [])
  17.  
  18.     Rev::[Int] [Int] -> [Int]
  19.     Rev [x:r]    list    =  Rev r [x : list]
  20.     Rev []        list    =  list
  21.  
  22.  
  23. //    The Start rule.
  24.  
  25. Start::Int
  26. Start = MyReverse NrOfTimes
  27.  
  28.